package com.deng.eventflow.core.tmf;

import java.util.Queue;

public class SinkLast extends Sink {
    /**
     * The last event (or array of events) received
     */
    protected Object[] m_last;

    /**
     * The number of events received so far
     */
    protected int m_eventCounter;

    /**
     * Creates a new sink last processor
     */
    public SinkLast()
    {
        super();
        m_last = null;
        m_eventCounter = 0;
    }

    /**
     * Creates a new sink last processor of given input arity
     * @param in_arity The input arity
     */
    public SinkLast(int in_arity)
    {
        super(in_arity);
        m_last = null;
        m_eventCounter = 0;
    }

    @Override
    public void reset()
    {
        super.reset();
        m_last = null;
        m_eventCounter = 0;
    }

    @Override
    protected boolean compute(Object[] inputs, Queue<Object[]> outputs)
    {
        m_last = inputs;
        return true;
    }

    public Object[] getLast()
    {
        return m_last;
    }

    @Override
    public SinkLast duplicate(boolean with_state)
    {
        return new SinkLast(getInputArity());
    }

    /**
     * @since 0.10.2
     */
    public Object printState()
    {
        return getInputArity();
    }

    /**
     * @since 0.10.2
     */
    @Override
    public SinkLast readState(Object o)
    {
        return new SinkLast(((Number) o).intValue());
    }
}
